import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_tv_widgets/widgets/formItem/entity/kq_form_entity.dart';
import 'package:kq_flutter_tv_widgets/widgets/formItem/kq_header_item_view.dart';
import 'package:kq_flutter_tv_widgets/widgets/sectionListView/kq_section_list_view.dart';

class SectionListView extends StatefulWidget {
  const SectionListView({super.key});

  @override
  State<SectionListView> createState() => _SectionListViewState();
}

class _SectionListViewState extends State<SectionListView> {
  List indexList = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
  List dataList = [
    ['1', '2', '3', '4', '5', '6'],
    ['1', '2', '3', '4', '5', '6', '7', '8'],
    ['1', '2', '3', '4', '5'],
    ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
    ['1', '2', '3', '4', '5', '6', '7', '8'],
    ['1', '2', '3', '4'],
    ['1', '2', '3', '4', '5', '6', '7'],
    ['1', '2', '3', '4', '5', '6', '7', '8'],
    ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
    ['1', '2', '3', '4', '5', '6'],
  ];

  Color getBackGroundColor(value) {
    Color color = KqThemeColors.textLightBlue;
    if (value == '1') {
      color = KqThemeColors.textGreen;
    } else if (value == '2') {
      color = KqThemeColors.bgWhite;
    } else if (value == '3') {
      color = KqThemeColors.textBlue;
    } else if (value == '4') {
      color = KqThemeColors.textYellow;
    } else if (value == '5') {
      color = KqThemeColors.textRed;
    }
    return color;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: KqSectionListView(
        section: 10,
        sectionHeight: 44.r,
        isSameHeight: true,
        indexList: indexList,
        isShowIndex: true,
        rowHeight: (section) {
          ///对应section分区单个row的高度
          return 44.r;
        },
        itemList: ((section) {
          ///对应section分区中的内容
          return dataList[section];
        }),
        headerBuilder: (int section) {
          return Container(
            color: KqThemeColors.text666,
            child: Text('分区:${section.toString()}'),
          );
        },
        itemBuilder: (section, row, object) {
          String number = object as String;
          return Container(
            alignment: Alignment.center,
            color: getBackGroundColor(number),
            child: Text(number),
          );
        },
        // listHeaderBuilder: () =>
        //     KqHeaderItemView(entity: KqFormEntity(title: '列表头部')),
        listFooterBuilder: () =>
            KqHeaderItemView(entity: KqFormEntity(title: '列表尾部')),
      ),
    );
  }
}
